const { connect } = dva;
const { Icon, Menu } = antd;

function AppMenu (props) {
    const { collapsed, menus, dispatch, pathNames } = props;
    return (
        <div>
            <div className={collapsed ? 'logo' : 'logo logo-background'}>
                <Icon
                    className="trigger"
                    type={collapsed ? 'menu-unfold' : 'menu-fold'}
                    onClick={() => dispatch({ type: 'app/toggle' })}
                />
            </div>
            <Menu
                theme="dark"
                mode='inline'
                inlineCollapsed={collapsed}
                defaultOpenKeys={collapsed ? [] : pathNames }
                selectedKeys={pathNames}
            >
                {menus}
            </Menu>
        </div>
    );
}

module.exports = connect(state => state.app)(AppMenu);